$(document).ready(function(){
   

});


  
function addProduct(type,showSucessBar){
      var url = $("#url4AddProduct").val();
      if(!type){
        $.ajax ({
            type: "GET",
            url: url,
            success: function (html)
            {
                $('#DAH').html(html);
                $(".chzn-select").chosen();
                $(".datepicker").datepicker();
                if(showSucessBar)
                    $('#DAH').prepend('<div class="nNote nSuccess hideit"><p><strong>SUCCESS: </strong> Product added successfully. </p></div>');     
            }
        });
      }else{
          var data = $("#form").serialize()
        $.ajax ({
            type: "POST",
            url: url,
            data :data,
            success: function (html)
            {
                if(html == "Done"){
                    addProduct(false, true);
                    $('html, body').animate({scrollTop:$('#rightSide').position().top}, 'slow');
                }
                else{
                    $('#DAH').html(html);
                    $(".chzn-select").chosen();
                    $(".datepicker").datepicker();
                }
            }
        });
      }
}



